package com.wolfheader.wolfgame;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.wolfheader.wolfgame.filter.AuthenticationFilter;
import com.wolfheader.wolfgame.interceptor.GameInterceptor;
import com.wolfheader.wolfgame.interceptor.TokenInterceptor;
import com.wolfheader.wolfgame.weixin.WeiXinUtils;

@SpringBootApplication
@EnableJpaRepositories
public class Application extends WebMvcConfigurerAdapter  {
	
	@Bean
	public AuthenticationFilter authenticationFilter() {
		return new AuthenticationFilter();

	}
	
	@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/game/**").addResourceLocations("file:/home/wolfgame/game/");
        super.addResourceHandlers(registry);
    }

	/**
	 * 配置拦截器
	 * 
	 * @author lance
	 * @param registry
	 */
	public void addInterceptors(InterceptorRegistry registry) {
		System.out.println("添加拦截器");
		registry.addInterceptor(new TokenInterceptor()).addPathPatterns("/admin/**");
		registry.addInterceptor(new GameInterceptor()).addPathPatterns("/game", "/game/**")
				.excludePathPatterns("/game/startWeixinInfo");
	}

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
		if (!WeiXinUtils.isStart) {
			WeiXinUtils.init();
			WeiXinUtils.isStart = true;
		}
	}
}
